package o;

import android.content.ContentResolver;
import android.content.UriMatcher;
import android.net.Uri;
import android.provider.ContactsContract.Contacts;
import androidx.annotation.NonNull;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class st extends sr<InputStream> {
    private static final UriMatcher ˊ = new UriMatcher(-1);

    protected /* synthetic */ Object ˊ(Uri uri, ContentResolver contentResolver) throws FileNotFoundException {
        return ˋ(uri, contentResolver);
    }

    protected /* synthetic */ void ˊ(Object obj) throws IOException {
        ॱ((InputStream) obj);
    }

    static {
        ˊ.addURI("com.android.contacts", "contacts/lookup/*/#", 1);
        ˊ.addURI("com.android.contacts", "contacts/lookup/*", 1);
        ˊ.addURI("com.android.contacts", "contacts/#/photo", 2);
        ˊ.addURI("com.android.contacts", "contacts/#", 3);
        ˊ.addURI("com.android.contacts", "contacts/#/display_photo", 4);
        ˊ.addURI("com.android.contacts", "phone_lookup/*", 5);
    }

    public st(ContentResolver contentResolver, Uri uri) {
        super(contentResolver, uri);
    }

    protected InputStream ˋ(Uri uri, ContentResolver contentResolver) throws FileNotFoundException {
        InputStream ˎ = ˎ(uri, contentResolver);
        if (ˎ != null) {
            return ˎ;
        }
        throw new FileNotFoundException("InputStream is null for " + uri);
    }

    private InputStream ˎ(Uri uri, ContentResolver contentResolver) throws FileNotFoundException {
        switch (ˊ.match(uri)) {
            case 1:
            case 5:
                Uri lookupContact = Contacts.lookupContact(contentResolver, uri);
                if (lookupContact != null) {
                    return ˋ(contentResolver, lookupContact);
                }
                throw new FileNotFoundException("Contact cannot be found");
            case 3:
                return ˋ(contentResolver, uri);
            default:
                return contentResolver.openInputStream(uri);
        }
    }

    private InputStream ˋ(ContentResolver contentResolver, Uri uri) {
        return Contacts.openContactPhotoInputStream(contentResolver, uri, true);
    }

    protected void ॱ(InputStream inputStream) throws IOException {
        inputStream.close();
    }

    @NonNull
    public Class<InputStream> ˋ() {
        return InputStream.class;
    }
}
